package com.cskaoyan.day17;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class WordsTest {
    public static void main(String[] args)  {
        String[] words = {"verb:eat", "verb:drink", "verb:sleep", "verb:play", "noun:rice", "noun:meat", "noun:hand", "noun:hair"};
        String path1 = "e:/Constructor/verb.txt";
        String path2 = "e:/Constructor/noun.txt";
        try (FileOutputStream verbStream = new FileOutputStream(path1, true);
             FileOutputStream nounStream = new FileOutputStream(path2, true)) {

            for (String word : words) {
                if (word.substring(0, 4).equals("verb")) {
                    verbStream.write(word.getBytes());
                    verbStream.write(System.lineSeparator().getBytes());
                    System.out.println(word+ "写入verb.txt");
                } else if (word.substring(0, 4).equals("noun")) {
                    nounStream.write(word.getBytes());
                    nounStream.write(System.lineSeparator().getBytes());
                    System.out.println(word+ "写入noun.txt");
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

